<?
include_once("../database.php");
include_once("../backend.php");
include_once("../login_management.php");
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/scoutingadmin.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Active Event | Admin | Team Spyder Scouting</title>
<!-- InstanceEndEditable -->

<link rel="stylesheet" type="text/css" href="../scouting.css"/>
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
</head>

<body>
<div class="main">
<div class="top2"><l>
<a class="navigation" href="./index.php">Home</a> | 
<a class="navigation" href="./register.php">Register a user</a> | 
<a class="navigation" href="./activeevent.php">Set Active Event</a> | 
<a class="navigation" href="./edit.php">Manage Users</a> | 
<a class="navigation" href="./teams.php">Input Teams</a> | 
<a class="navigation" href="cleanup.php"> Clean up DB</a> | 
<a class="navigation" href="./eventsetup/index.php"> Event Setup </a> | 
<a class="navigation" href="../index.php"> Main </a> | 
<script type="text/javascript">
function LoadLogin()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("content").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","login.php",true);
xmlhttp.send();
}
</script>

<?
if($logged_in)
{
	echo "<l> Welcome,&nbsp;" . $_SESSION['username'] . " </l>";
	echo "<a class=\"navigation\" href=\"./logout.php\">Log&nbsp;out</a>\n";
}
else
{
	echo "<l> You&nbsp;are&nbsp;not&nbsp;logged&nbsp;in. </l>";
	echo "<a class=\"navigation\" href=\"#\" onclick=\"LoadLogin()\">Log in</a>\n";
}

?>
</l>
</div>
<div class="content"><!-- InstanceBeginEditable name="Content" -->
<h1>Active Competition Selection</h1>
<?
if($logged_in)
{
	if(isset($_GET['event']))
	{
		$q="UPDATE spyderscoutingsettings
SET name='datatable', value='" . $_GET['event'] . "'
WHERE name='datatable'";
		if($_GET['type']=="FRC")
		{
			$q2="UPDATE spyderscoutingsettings SET name='numteams', value='6' WHERE name='numteams'";
		}
		else
		{
			$q2="UPDATE spyderscoutingsettings SET name='numteams', value='4' WHERE name='numteams'";
		}
	$result=mysql_query($q) or die(mysql_error());
	$result2=mysql_query($q2) or die(mysql_error());
	echo "<p>Successfully set Active Competition</p>";
	}
	else
	{
	$q="SELECT * FROM eventlist ORDER BY year DESC";
	$result=mysql_query($q) or die(mysql_error());
	?>
    <table border="2">
    <tr class="tableheader">
    <td>Event Name</td>
    <td>Event Year</td>
    <td>Event Type</td>
    <td>Set Active</td>
    </tr>
    <?
	$lastyear="luls";
	while($row=mysql_fetch_array($result))
	{
		if($lastyear!=$row['year'] & $lastyear!="luls")
		{
			?>
    <tr class="tableheader">
    <td>Event Name</td>
    <td>Event Year</td>
    <td>Event Type</td>
    <td>Set Active</td>
    </tr>
    <?
		}
		echo "<tr>\n";
		echo "<td>" . $row['event'] . "</td>";
		echo "<td>" . $row['year'] . "</td>";
		echo "<td>" . $row['competition'] . "</td>";
		if($row['competition']=="FRC")
		{
			echo "<td>" . "<a href=\"activeevent.php?event=".$row['datatable']."&type=FRC\">set active</a>" . "</td>";
		}
		else
		{
			echo "<td>" . "<a href=\"activeevent.php?event=".$row['datatable']."&type=VEX\">set active</a>" . "</td>";
		}
		$lastyear=$row['year'];
	}
	?>
    </table>
    <?
	}
}
else
{
	displayLogin();
}
mysql_close();
?>
<!-- InstanceEndEditable -->
</div>
</div>

</body>
<!-- InstanceEnd --></html>
